<template>
  <!-- <div class="objsubMain">
      <div class="objsubContent"> -->
  <el-dialog
    title="批量设置题组分配方式"
    width="500px"
    :visible.sync="taskwayishow"
    :before-close="handleClose"
  >
    <div class="elradigroup">
      <span>请选择分配方式</span>
      <el-radio-group v-model="tasktype" @change="tasktypechange">
        <el-radio :label="1">自动分题</el-radio>
        <el-radio :label="2">平均分题</el-radio>
        <el-radio :label="3">效率分题</el-radio>
      </el-radio-group>
    </div>
    <div class="objbtnbox" v-if="questiongroup.siglequestiontype == 1">
      <span @click="alltaskschoolSure">保存并退出</span>
      <span @click="skipquestion">跳转下题</span>
      <span @click="alltaskschoolBack">返回</span>
    </div>
    <div class="objbtnbox" v-else>
      <span @click="alltaskschoolSure1">保存</span>
      <span @click="alltaskschoolBack">返回</span>
    </div>
  </el-dialog>
  <!-- </div>
    </div> -->
</template>

<script>
import { mount } from "sortablejs";
import {
  singQuestionassignment,
  batchclickAllocation,
} from "../../api/task/task.js";
export default {
  props: {
    taskwayishow: false,
    questiongroup: {
      type: Object,
      default: () => {},
    },
    tasklist: {
      type: Array,
      default: () => [],
    },
    multipleSelection: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      tasktype: 0,
      questionindex: 0,
    };
  },
  mounted() {
    this.questionindex = this.questiongroup.questionindex;
  },
  methods: {
    handleClose() {
      this.$emit("taskwaySureemit", 2);
    },
    alltaskschoolSure() {
      if (this.tasktype == 0) {
        this.$message({
          message: "请选择分配方式",
          type: "warning",
        });
        return;
      }
      let obj = {
        id: this.questiongroup.questionid,
        assignmentType: this.tasktype,
      };
      singQuestionassignment(obj).then((res) => {
        if (res.code == 200) {
          this.$emit("taskwaySureemit", 1);
        }
      });
    },
    //跳转下一题
    skipquestion() {
      if (this.tasktype == 0) {
        this.$message({
          message: "请选择分配方式",
          type: "warning",
        });
        return;
      }
      if (this.questionindex <= this.tasklist.length - 1) {
        let obj = {
          id: this.tasklist[this.questionindex].id,
          assignmentType: this.tasktype,
        };
        singQuestionassignment(obj).then((res) => {
          if (res.code == 200) {
            this.questionindex++;
          }
        });
      } else {
        this.$message({
          message: "最后一道题了",
          type: "warning",
        });
        setTimeout(() => {
          this.$emit("taskwaySureemit", 1);
        }, 100);
      }
    },
    alltaskschoolBack() {
      this.$emit("taskwaySureemit", 2);
    },
    tasktypechange(val) {
      this.tasktype = val;
      // this.$emit('tasktypechange',val)
    },
    alltaskschoolSure1() {
      if (this.tasktype == 0) {
        this.$message({
          message: "请选择分配方式",
          type: "warning",
        });
        return;
      }
      let ids = this.multipleSelection.map((item) => {
        return {
          id: item.id,
          assignmentType: this.tasktype,
        };
      });
      batchclickAllocation(ids).then((res) => {
        if (res.code == 200) {
          this.$emit("taskwaySureemit", 1);
          this.$message({
            message: "修改分题模式成功",
            type: "success",
          });
        }
      });
    },
  },
};
</script>

<style scoped>
.objsubMain {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
}
.objsubContent {
  box-sizing: border-box;
  width: 500px;
  height: 200px;
  background: #ffffff;
  box-shadow: 0px 4px 16px 0px rgba(85, 114, 146, 0.1);
  border-radius: 10px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 24px;
}
.objsubContent h3 {
  font-size: 18px;
  font-weight: normal;
}
.objsubattention {
  display: flex;
  font-size: 14px;
  color: #619cf5;
  padding: 10px 0 24px;
}
.custom-table {
  width: 100%;
  border: 1px solid rgba(216, 228, 240, 0.34);
  border-right: none;
  border-bottom: none;
}
/* 自定义表格内部元素的样式 */
.custom-table >>> .el-table__header-wrapper th {
  background-color: #e8f0fa;
  height: 42px;
  padding: 0;
  text-align: center;
  font-weight: normal;
}
.custom-table >>> .el-table th.el-table__cell.is-leaf,
.custom-table >>> .el-table td.el-table__cell {
  border-bottom: none;
}
.custom-table >>> .el-table__row td {
  height: 42px;
  padding: 0;
  text-align: center;
  border-right: solid 1px rgba(216, 228, 240, 0.5);
  font-size: 14px;
}
.el-table .warning-row {
  background: #ffffff;
}
.el-table .success-row {
  background: #d8e4f0;
}
.el-table .el-table__cell {
  padding: 8px 0;
}
.objbtnbox {
  display: flex;
  align-items: center;
  padding-top: 30px;
}
.objbtnbox span {
  width: 84px;
  height: 34px;
  background: #1a48db;
  border-radius: 4px;
  text-align: center;
  line-height: 34px;
  color: #fff;
  display: inline-block;
  margin-right: 15px;
  cursor: pointer;
  font-size: 14px;
}
.objbtnbox span:last-child {
  background: #eee;
  color: #666;
}
.elradigroup {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.elradigroup span {
  font-size: 14px;
}
</style>